using System;
using System.Text;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using RealState.BusinessObjects;

namespace RealState.DAL
{
	public class ContentExtrasDAO
	{
		public ContentExtrasDAO()
		{
			DbProviderHelper.GetConnection();
		}
		public List<ContentExtras> GetContentExtrass()
		{
			try
			{
				List<ContentExtras> lstContentExtrass = new List<ContentExtras>();
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("SELECTContentExtrass",CommandType.StoredProcedure);
				DbDataReader oDbDataReader = DbProviderHelper.ExecuteReader(oDbCommand);
				while (oDbDataReader.Read())
				{
					ContentExtras oContentExtras = new ContentExtras();
					oContentExtras.ContentId = Convert.ToInt32(oDbDataReader["ContentId"]);
					oContentExtras.CompanyName = Convert.ToString(oDbDataReader["CompanyName"]);
					oContentExtras.CompanyAddress = Convert.ToString(oDbDataReader["CompanyAddress"]);
					oContentExtras.Tel = Convert.ToString(oDbDataReader["Tel"]);

					if(oDbDataReader["Fax"] != DBNull.Value)
						oContentExtras.Fax = Convert.ToString(oDbDataReader["Fax"]);

					if(oDbDataReader["Email"] != DBNull.Value)
						oContentExtras.Email = Convert.ToString(oDbDataReader["Email"]);

					if(oDbDataReader["Website"] != DBNull.Value)
						oContentExtras.Website = Convert.ToString(oDbDataReader["Website"]);
					oContentExtras.BusinessOwner = Convert.ToString(oDbDataReader["BusinessOwner"]);
					oContentExtras.TaxCode = Convert.ToString(oDbDataReader["TaxCode"]);

					if(oDbDataReader["StartTime"] != DBNull.Value)
						oContentExtras.StartTime = Convert.ToDateTime(oDbDataReader["StartTime"]);

					if(oDbDataReader["Description"] != DBNull.Value)
						oContentExtras.Description = Convert.ToString(oDbDataReader["Description"]);
					oContentExtras.Status = Convert.ToString(oDbDataReader["Status"]);

					if(oDbDataReader["Revenue"] != DBNull.Value)
						oContentExtras.Revenue = Convert.ToString(oDbDataReader["Revenue"]);

					if(oDbDataReader["LastRevenue"] != DBNull.Value)
						oContentExtras.LastRevenue = Convert.ToString(oDbDataReader["LastRevenue"]);

					if(oDbDataReader["AnnualProfit"] != DBNull.Value)
						oContentExtras.AnnualProfit = Convert.ToString(oDbDataReader["AnnualProfit"]);

					if(oDbDataReader["LastAnualProfit"] != DBNull.Value)
						oContentExtras.LastAnualProfit = Convert.ToString(oDbDataReader["LastAnualProfit"]);

					if(oDbDataReader["Assets"] != DBNull.Value)
						oContentExtras.Assets = Convert.ToString(oDbDataReader["Assets"]);
					oContentExtras.SaleType = Convert.ToString(oDbDataReader["SaleType"]);
					oContentExtras.Reason = Convert.ToString(oDbDataReader["Reason"]);

					if(oDbDataReader["IsAuction"] != DBNull.Value)
						oContentExtras.IsAuction = Convert.ToBoolean(oDbDataReader["IsAuction"]);

					if(oDbDataReader["Price"] != DBNull.Value)
						oContentExtras.Price =Convert.ToInt64( oDbDataReader["Price"]);

					if(oDbDataReader["TransType"] != DBNull.Value)
						oContentExtras.TransType = Convert.ToString(oDbDataReader["TransType"]);

					if(oDbDataReader["ProjectTitle"] != DBNull.Value)
						oContentExtras.ProjectTitle = Convert.ToString(oDbDataReader["ProjectTitle"]);

					if(oDbDataReader["Investor"] != DBNull.Value)
						oContentExtras.Investor = Convert.ToString(oDbDataReader["Investor"]);

					if(oDbDataReader["Location"] != DBNull.Value)
						oContentExtras.Location = Convert.ToString(oDbDataReader["Location"]);

					if(oDbDataReader["Note"] != DBNull.Value)
						oContentExtras.Note = Convert.ToString(oDbDataReader["Note"]);
					lstContentExtrass.Add(oContentExtras);
				}
				oDbDataReader.Close();
				return lstContentExtrass;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public ContentExtras GetContentExtras(int ContentId)
		{
			try
			{
				ContentExtras oContentExtras = new ContentExtras();
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("SELECTContentExtras",CommandType.StoredProcedure);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ContentId",DbType.Int32,ContentId));
				DbDataReader oDbDataReader = DbProviderHelper.ExecuteReader(oDbCommand);
				while (oDbDataReader.Read())
				{
					oContentExtras.ContentId = Convert.ToInt32(oDbDataReader["ContentId"]);
					oContentExtras.CompanyName = Convert.ToString(oDbDataReader["CompanyName"]);
					oContentExtras.CompanyAddress = Convert.ToString(oDbDataReader["CompanyAddress"]);
					oContentExtras.Tel = Convert.ToString(oDbDataReader["Tel"]);

					if(oDbDataReader["Fax"] != DBNull.Value)
						oContentExtras.Fax = Convert.ToString(oDbDataReader["Fax"]);

					if(oDbDataReader["Email"] != DBNull.Value)
						oContentExtras.Email = Convert.ToString(oDbDataReader["Email"]);

					if(oDbDataReader["Website"] != DBNull.Value)
						oContentExtras.Website = Convert.ToString(oDbDataReader["Website"]);
					oContentExtras.BusinessOwner = Convert.ToString(oDbDataReader["BusinessOwner"]);
					oContentExtras.TaxCode = Convert.ToString(oDbDataReader["TaxCode"]);

					if(oDbDataReader["StartTime"] != DBNull.Value)
						oContentExtras.StartTime = Convert.ToDateTime(oDbDataReader["StartTime"]);

					if(oDbDataReader["Description"] != DBNull.Value)
						oContentExtras.Description = Convert.ToString(oDbDataReader["Description"]);
					oContentExtras.Status = Convert.ToString(oDbDataReader["Status"]);

					if(oDbDataReader["Revenue"] != DBNull.Value)
						oContentExtras.Revenue = Convert.ToString(oDbDataReader["Revenue"]);

					if(oDbDataReader["LastRevenue"] != DBNull.Value)
						oContentExtras.LastRevenue = Convert.ToString(oDbDataReader["LastRevenue"]);

					if(oDbDataReader["AnnualProfit"] != DBNull.Value)
						oContentExtras.AnnualProfit = Convert.ToString(oDbDataReader["AnnualProfit"]);

					if(oDbDataReader["LastAnualProfit"] != DBNull.Value)
						oContentExtras.LastAnualProfit = Convert.ToString(oDbDataReader["LastAnualProfit"]);

					if(oDbDataReader["Assets"] != DBNull.Value)
						oContentExtras.Assets = Convert.ToString(oDbDataReader["Assets"]);
					oContentExtras.SaleType = Convert.ToString(oDbDataReader["SaleType"]);
					oContentExtras.Reason = Convert.ToString(oDbDataReader["Reason"]);

					if(oDbDataReader["IsAuction"] != DBNull.Value)
						oContentExtras.IsAuction = Convert.ToBoolean(oDbDataReader["IsAuction"]);

					if(oDbDataReader["Price"] != DBNull.Value)
						oContentExtras.Price = Convert.ToInt64( oDbDataReader["Price"]);

					if(oDbDataReader["TransType"] != DBNull.Value)
						oContentExtras.TransType = Convert.ToString(oDbDataReader["TransType"]);

					if(oDbDataReader["ProjectTitle"] != DBNull.Value)
						oContentExtras.ProjectTitle = Convert.ToString(oDbDataReader["ProjectTitle"]);

					if(oDbDataReader["Investor"] != DBNull.Value)
						oContentExtras.Investor = Convert.ToString(oDbDataReader["Investor"]);

					if(oDbDataReader["Location"] != DBNull.Value)
						oContentExtras.Location = Convert.ToString(oDbDataReader["Location"]);

					if(oDbDataReader["Note"] != DBNull.Value)
						oContentExtras.Note = Convert.ToString(oDbDataReader["Note"]);
				}
				oDbDataReader.Close();
				return oContentExtras;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int AddContentExtras(ContentExtras oContentExtras)
		{
			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("INSERTContentExtras",CommandType.StoredProcedure);
                oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ContentId", DbType.Int32, oContentExtras.ContentId));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CompanyName",DbType.String,oContentExtras.CompanyName));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CompanyAddress",DbType.String,oContentExtras.CompanyAddress));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Tel",DbType.String,oContentExtras.Tel));
				if (oContentExtras.Fax!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Fax",DbType.String,oContentExtras.Fax));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Fax",DbType.String,DBNull.Value));
				if (oContentExtras.Email!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Email",DbType.String,oContentExtras.Email));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Email",DbType.String,DBNull.Value));
				if (oContentExtras.Website!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Website",DbType.String,oContentExtras.Website));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Website",DbType.String,DBNull.Value));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@BusinessOwner",DbType.String,oContentExtras.BusinessOwner));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TaxCode",DbType.String,oContentExtras.TaxCode));
				if (oContentExtras.StartTime!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@StartTime",DbType.DateTime,oContentExtras.StartTime));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@StartTime",DbType.DateTime,DBNull.Value));
				if (oContentExtras.Description!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Description",DbType.String,oContentExtras.Description));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Description",DbType.String,DBNull.Value));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Status",DbType.String,oContentExtras.Status));
				if (oContentExtras.Revenue!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Revenue",DbType.String,oContentExtras.Revenue));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Revenue",DbType.String,DBNull.Value));
				if (oContentExtras.LastRevenue!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@LastRevenue",DbType.String,oContentExtras.LastRevenue));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@LastRevenue",DbType.String,DBNull.Value));
				if (oContentExtras.AnnualProfit!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@AnnualProfit",DbType.String,oContentExtras.AnnualProfit));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@AnnualProfit",DbType.String,DBNull.Value));
				if (oContentExtras.LastAnualProfit!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@LastAnualProfit",DbType.String,oContentExtras.LastAnualProfit));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@LastAnualProfit",DbType.String,DBNull.Value));
				if (oContentExtras.Assets!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Assets",DbType.String,oContentExtras.Assets));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Assets",DbType.String,DBNull.Value));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SaleType",DbType.String,oContentExtras.SaleType));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Reason",DbType.String,oContentExtras.Reason));
				if (oContentExtras.IsAuction.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@IsAuction",DbType.Boolean,oContentExtras.IsAuction));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@IsAuction",DbType.Boolean,DBNull.Value));
				if (oContentExtras.Price>0)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Price",DbType.Int64,oContentExtras.Price));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Price",DbType.Int64,DBNull.Value));
				if (oContentExtras.TransType!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TransType",DbType.String,oContentExtras.TransType));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TransType",DbType.String,DBNull.Value));
				if (oContentExtras.ProjectTitle!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ProjectTitle",DbType.String,oContentExtras.ProjectTitle));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ProjectTitle",DbType.String,DBNull.Value));
				if (oContentExtras.Investor!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Investor",DbType.String,oContentExtras.Investor));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Investor",DbType.String,DBNull.Value));
				if (oContentExtras.Location!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Location",DbType.String,oContentExtras.Location));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Location",DbType.String,DBNull.Value));
				if (oContentExtras.Note!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Note",DbType.String,oContentExtras.Note));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Note",DbType.String,DBNull.Value));

				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int UpdateContentExtras(ContentExtras oContentExtras)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("UPDATEContentExtras",CommandType.StoredProcedure);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CompanyName",DbType.String,oContentExtras.CompanyName));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CompanyAddress",DbType.String,oContentExtras.CompanyAddress));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Tel",DbType.String,oContentExtras.Tel));
				if (oContentExtras.Fax!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Fax",DbType.String,oContentExtras.Fax));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Fax",DbType.String,DBNull.Value));
				if (oContentExtras.Email!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Email",DbType.String,oContentExtras.Email));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Email",DbType.String,DBNull.Value));
				if (oContentExtras.Website!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Website",DbType.String,oContentExtras.Website));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Website",DbType.String,DBNull.Value));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@BusinessOwner",DbType.String,oContentExtras.BusinessOwner));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TaxCode",DbType.String,oContentExtras.TaxCode));
				if (oContentExtras.StartTime!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@StartTime",DbType.String,oContentExtras.StartTime));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@StartTime",DbType.String,DBNull.Value));
				if (oContentExtras.Description!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Description",DbType.String,oContentExtras.Description));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Description",DbType.String,DBNull.Value));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Status",DbType.String,oContentExtras.Status));
				if (oContentExtras.Revenue!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Revenue",DbType.String,oContentExtras.Revenue));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Revenue",DbType.String,DBNull.Value));
				if (oContentExtras.LastRevenue!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@LastRevenue",DbType.String,oContentExtras.LastRevenue));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@LastRevenue",DbType.String,DBNull.Value));
				if (oContentExtras.AnnualProfit!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@AnnualProfit",DbType.String,oContentExtras.AnnualProfit));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@AnnualProfit",DbType.String,DBNull.Value));
				if (oContentExtras.LastAnualProfit!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@LastAnualProfit",DbType.String,oContentExtras.LastAnualProfit));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@LastAnualProfit",DbType.String,DBNull.Value));
				if (oContentExtras.Assets!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Assets",DbType.String,oContentExtras.Assets));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Assets",DbType.String,DBNull.Value));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@SaleType",DbType.String,oContentExtras.SaleType));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Reason",DbType.String,oContentExtras.Reason));
				if (oContentExtras.IsAuction.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@IsAuction",DbType.Boolean,oContentExtras.IsAuction));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@IsAuction",DbType.Boolean,DBNull.Value));
				if (oContentExtras.Price!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Price",DbType.String,oContentExtras.Price));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Price",DbType.String,DBNull.Value));
				if (oContentExtras.TransType!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TransType",DbType.String,oContentExtras.TransType));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TransType",DbType.String,DBNull.Value));
				if (oContentExtras.ProjectTitle!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ProjectTitle",DbType.String,oContentExtras.ProjectTitle));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ProjectTitle",DbType.String,DBNull.Value));
				if (oContentExtras.Investor!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Investor",DbType.String,oContentExtras.Investor));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Investor",DbType.String,DBNull.Value));
				if (oContentExtras.Location!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Location",DbType.String,oContentExtras.Location));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Location",DbType.String,DBNull.Value));
				if (oContentExtras.Note!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Note",DbType.String,oContentExtras.Note));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Note",DbType.String,DBNull.Value));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ContentId",DbType.Int32,oContentExtras.ContentId));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int RemoveContentExtras(ContentExtras oContentExtras)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("DELETEContentExtras",CommandType.StoredProcedure);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ContentId",DbType.Int32,oContentExtras.ContentId));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int RemoveContentExtras(int ContentId)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("DELETEContentExtras",CommandType.StoredProcedure);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ContentId",DbType.Int32,ContentId));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
	}
}
